﻿#region

using System;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using CuongHanh.Context;
using CuongHanh.Models;
using CuongHanh.Models.View;

#endregion

namespace CuongHanh
{
    public class AppUtil
    {
        public static string CurrentDomain = ConfigurationManager.AppSettings["CurrentUrl"] ?? "http://cuonghanh.vn";

        public const string JWELLERY_ROUTE_VI = "trang-suc";
        public const string JWELLERY_ROUTE_EN = "jewellery";

        public const string USER_ID = "USER_ID";

        public const string USERNAME = "USERNAME";

        public const string ARTICLE_IMAGE = "~/Content/Images/Article/";

        public const int WIDTH_LAGRE = 850;

        public const int HEIGHT_LAGRE = 850;

        public const int WIDTH_SMALL = 290;

        public const int HEIGHT_SMALL = 290;

        public const int WIDTH_THUMNAIL = 48;

        public const int HEIGHT_THUMNAIL = 48;

        public const int WIDTH_THUMNAIL_BANNER = 64;

        #region Product

        public const string GEM_IMAGE_PATH = "~/Content/Images/Gem/";

        public const string LARGE_IMAGE_PATH = "~/Content/Images/Large/";

        public const string SMALL_IMAGE_PATH = "~/Content/Images/Small/";

        public const string THUMNAIL_IMAGE_PATH = "~/Content/Images/Thumnail/";

        #endregion

        #region Banner

        public const string THUMNAIL_BANNER_MAIN_PATH = "~/Content/Images/Banner/Thumnail/Main/";

        public const string THUMNAIL_BANNER_GEM_PATH = "~/Content/Images/Banner/Thumnail/Gem/";

        public const string THUMNAIL_BANNER_WOOD_PATH = "~/Content/Images/Banner/Thumnail/Wood/";

        public const string THUMNAIL_BANNER_STONE_PATH = "~/Content/Images/Banner/Thumnail/Stone/";

        public const string BANNER_MAIN_PATH = "~/Content/Images/Banner/Large/Main/";

        public const string BANNER_GEM_PATH = "~/Content/Images/Banner/Large/Gem/";

        public const string BANNER_WOOD_PATH = "~/Content/Images/Banner/Large/Wood/";

        public const string BANNER_STONE_PATH = "~/Content/Images/Banner/Large/Stone/";

        #endregion

        #region Const

        public const string PLACE = "PLACE";

        #endregion

        #region Main

        public const int MAIN_CODE = 0;

        public const string MAIN_INDEX = "trangchu";

        public const string MAIN_INTRODUCE = "gioithieu";

        public const string MAIN_SERVICE = "dichvu";

        public const string MAIN_CONTACT = "lienhe";

        #endregion

        #region Gem

        public const int GEM_CODE = 1;

        public const string GEM_NAME = "trang-suc";

        #endregion

        #region Wood

        public const int WOOD_CODE = 2;

        public const string WOOD_NAME = "go-my-nghe-noi-that";

        #endregion

        #region Stone

        public const int STONE_CODE = 3;

        public const string STONE_NAME = "da-my-nghe";

        #endregion

        #region Language

        public const string LANGUAGE = "LANGUAGE";

        public const string LANGUAGE_VI = "";

        public const string LANGUAGE_EN = "en";

        public const string LANGUAGE_ZH = "zh";

        #endregion

        #region Format

        public const string NUMBER_FORMAT = "#,###";

        public const string DATE_FORMAT = "yyyy-MM-dd";

        public const string DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

        public const string DATE_TIME_FORMAT2 = "yyyy-MM-dd HH:mm";

        public const string DATE_TIME_FORMAT3 = "yyyyMMddHHmmss";

        public static string TiGiaUrl = string.Empty;

        public static string FormatNumber(long value)
        {
            return string.Format("{0:#,###}",
                    value);
        }

        public static string FormatNumber(int value)
        {
            return string.Format("{0:#,###}",
                    value);
        }

        #endregion

        public static string GetBannerPath(int branchId)
        {
            switch (branchId)
            {
                case MAIN_CODE:
                    return BANNER_MAIN_PATH;
                case GEM_CODE:
                    return BANNER_GEM_PATH;
                case WOOD_CODE:
                    return BANNER_WOOD_PATH;
                case STONE_CODE:
                    return BANNER_STONE_PATH;
            }
            return string.Empty;
        }

        public static string GetThumnailBannerPath(int branchId)
        {
            switch (branchId)
            {
                case MAIN_CODE:
                    return THUMNAIL_BANNER_MAIN_PATH;
                case GEM_CODE:
                    return THUMNAIL_BANNER_GEM_PATH;
                case WOOD_CODE:
                    return THUMNAIL_BANNER_WOOD_PATH;
                case STONE_CODE:
                    return THUMNAIL_BANNER_STONE_PATH;
            }
            return string.Empty;
        }

        #region Sub Category

        public static Func<SubCategory, string, string> SubCategoryName = (p,
                l) => l == LANGUAGE_EN
                                ? p.NameEn
                                : p.NameVi;

        public static Func<SubCategoryView, string, string> SubCategoryViewName = (p,
                l) => l == LANGUAGE_EN
                                ? p.NameEn
                                : p.NameVi;

        public static Func<CategoryView, string, string> CategoryViewName = (p,
                l) =>l == LANGUAGE_EN
                                ? p.NameEn
                                : p.NameVi;

        public static Func<Category, string, string> CategoryName = (p,
                l) => l == LANGUAGE_EN
                                ? p.NameEn
                                : p.NameVi;

        public static Func<Product, string, string> ProductViewName = (p,
                l) => l == LANGUAGE_EN
                                ? p.NameEn
                                : p.NameVi;

        //public static string GetSubCategoryName(int id,
        //        string l)
        //{
        //    return SubCategoryName(CacheContext<SubCategory>.Singleton.GetObject(id),
        //            l);
        //}

        #endregion

        //public static string GetMd5(string text)
        //{
        //    // step 1, calculate MD5 hash from input
        //    MD5 md5 = System.Security.Cryptography.MD5.Create();
        //    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(text);
        //    byte[] hash = md5.ComputeHash(inputBytes);

        //    // step 2, convert byte array to hex string
        //    StringBuilder sb = new StringBuilder();
        //    foreach (byte t in hash)
        //    {
        //        sb.Append(t.ToString("X2"));
        //    }
        //    return sb.ToString();
        //}


        #region TiGia

        public const string TI_GIA_PATH = "~/App_ReSource/tigia.txt";


        public static double TIGIA = 0;


        #endregion

        #region Price Of Different Size

        /// <summary>
        /// Kich thuot gia ban dau cua nhan nam
        /// </summary>
        public const int NORMAL_SIZE_MEN_RING = 13;
        /// <summary>
        /// Kich thuot gia ban dau cua nhan nu
        /// </summary>
        public const int NORMAL_SIZE_WOMENS_RING = 10;
        /// <summary>
        /// Kich thuot gia ban dau cua day chuyen
        /// </summary>
        public const int NORMAL_SIZE_NECKLACE = 45;
        /// <summary>
        /// Kich thuot gia ban dau cua vong
        /// </summary>
        public const int NORMAL_SIZE_BRACELETS = 50;
        #endregion


        #region Customer format login



        public const string CUSTOMERID = "CustomerId";
        public const string CUSTOMERNAME = "CustomerName";
        #endregion

        #region Gio Hang

        public const string GEM_BAG = "OrderForGem";
        #endregion
        public static void InIt(HttpServerUtility server)
        {
            TIGIA = ReadAndWriteFile.Read(server.MapPath(TI_GIA_PATH));
        }
    }
}
